home *** CD-ROM | disk | FTP | other *** search
Wrap
global LevelList, anchorList, JumpList on CreateAllMenus set theOriginalTextList to ["Installation.txt", "1st Look.txt", "Source & Center.txt", "Explore.txt", "Inspiration.txt"] set theStrippedTextList to ["README1 text stripped", "README2 text stripped", "README3 text stripped", "README4 text stripped", "README5 text stripped"] set StructuresList to ["Menu 1 List Structure", "Menu 2 List Structure", "Menu 3 List Structure", "Menu 4 List Structure", "Menu 5 List Structure"] set anchorList to [:] set JumpList to [:] repeat with i = 1 to count(theOriginalTextList) set LevelList to [i] set theOriginalCastText to getFileText(getAt(theOriginalTextList, i)) if theOriginalCastText = -1 then alert("Could not read the last file... aborting file parsing.") exit repeat end if set theDestination to getAt(StructuresList, i) set DestString to word 1 to 2 of theDestination set StrippedTextCast to the number of member (getAt(theStrippedTextList, i) & ".1") put "Beginning to parse: " & DestString put "File size: " & the number of chars in theOriginalCastText & " characters" set theNewMenu to CreateMainMenu(theOriginalCastText, StrippedTextCast) set the text of cast theDestination to string(theNewMenu) put "Stripping control characters from " & DestString & "..." set tempText to stripControlChars(theOriginalCastText) set kLimit to 32 * 1024 repeat with j = 1 to 6 set castOffset to j - 1 set theCastNum to StrippedTextCast + castOffset set firstChar to (kLimit * castOffset) + 1 set lastChar to kLimit * j set the text of cast theCastNum to char firstChar to lastChar of tempText end repeat set theOriginalCastText to EMPTY set tempText to EMPTY end repeat put "... writing out list of hypertext anchors..." put anchorList into field "Anchor List" put "... writing out list of hypertext jumps..." put JumpList into field "Jump List" put "Done compiling menus!" end on getFileText suggestedName set myFileio to new(xtra("fileio")) openFile(myFileio, the pathName & "text files:" & suggestedName, 1) if status(myFileio) <> 0 then alert("I was unable to find the '" & suggestedName & "' text file. Click OK then find that text file in the next dialog box.") set aFile to displayOpen(myFileio) openFile(myFileio, aFile, 1) end if if status(myFileio) <> 0 then alert("Unable to read the file successfully!") set myFileio to 0 return -1 end if set theFileText to readFile(myFileio) set myFileio to 0 return theFileText end on CreateMainMenu theText, aStrippedCastNum set theCastNum to aStrippedCastNum append(LevelList, 0) set theMenu to doCreateMainMenu(theText, 1, 1, theCastNum) return theMenu end on doCreateMainMenu aBigTextBlock, currentLevel, currentLine, theStrippedCastNum set newMenuList to [] set newMenu to [:] set newPageList to [] set newPage to [:] set pageCounter to 0 set thisPageImage to EMPTY set thisPageMovie to EMPTY set lastInterestingLine to 0 set maxLines to the number of lines in aBigTextBlock set TenPercentLines to maxLines / 10 cursor(4) repeat while currentLine <= maxLines set theLine to line currentLine of aBigTextBlock if theLine contains "{" & currentLevel & "}" then set newMenuList to finishMenuLevel(newMenu, newPage, newPageList, newMenuList) set newMenu to [:] set newPageList to [] set newPage to [:] set lastOne to count(LevelList) setAt(LevelList, lastOne, getAt(LevelList, lastOne) + 1) set thisHeader to stripChars(theLine, "{", "}") set tempStr to EMPTY repeat with i = 1 to currentLevel * 3 put " " after tempStr end repeat set thisHeader to tempStr & thisHeader put thisHeader after tempStr addProp(newMenu, #MenuHeading, thisHeader) set pageCounter to 0 set lastInterestingLine to currentLine end if if theLine contains "{" & currentLevel + 1 & "}" then set tempHeader to getProp(newMenu, #MenuHeading) set theCharLoc to (currentLevel * 3) - 2 put "+" into char theCharLoc to theCharLoc + 1 of tempHeader setProp(newMenu, #MenuHeading, tempHeader) append(LevelList, 0) set subMenuAndLines to doCreateMainMenu(aBigTextBlock, currentLevel + 1, currentLine, theStrippedCastNum) set theSubMenu to getAt(subMenuAndLines, 1) set newCurLine to getAt(subMenuAndLines, 2) addProp(newMenu, #SubMenu, theSubMenu) set currentLine to newCurLine - 1 set lastInterestingLine to currentLine end if set lev1 to "{" & currentLevel - 1 & "}" set lev2 to "{" & currentLevel - 2 & "}" set lev3 to "{" & currentLevel - 3 & "}" if (theLine contains lev1) or (theLine contains lev2) or (theLine contains lev3) then set newMenuList to finishMenuLevel(newMenu, newPage, newPageList, newMenuList) deleteAt(LevelList, count(LevelList)) return [newMenuList, currentLine] end if if theLine contains "{a" then set anchorOffset to offset("{a", theLine) + 2 set anchorEnd to offset("}", theLine) set anchorNum to value(char anchorOffset to anchorEnd - 1 of theLine) set tempLevelList to value(string(LevelList)) append(tempLevelList, pageCounter + 1) addAnchorToList(anchorNum, tempLevelList) end if if theLine contains "{j" then repeat while theLine contains "{j" set jumpOffset to offset("{j", theLine) + 2 set jumpEnd to offset("}", theLine) set jumpNum to value(char jumpOffset to jumpEnd - 1 of theLine) repeat with wordCount = 1 to the number of words in theLine if word wordCount of theLine contains "{j" then set lastWordNum to wordCount - 1 repeat with hyperWords = lastWordNum down to 1 if word hyperWords of theLine starts "<" then set firstWordNum to hyperWords exit repeat end if end repeat end if end repeat delete char jumpOffset - 2 to jumpEnd of theLine set tempLevelList to value(string(LevelList)) append(tempLevelList, pageCounter + 1) append(tempLevelList, currentLine - lastInterestingLine) repeat with thisWord = firstWordNum to lastWordNum append(tempLevelList, thisWord) set hyperWord to word thisWord of theLine if hyperWord contains "<" then delete char offset("<", hyperWord) of hyperWord end if if hyperWord contains ">" then delete char offset(">", hyperWord) of hyperWord end if addJumptoList(hyperWord, jumpNum, tempLevelList) deleteAt(tempLevelList, count(tempLevelList)) end repeat end repeat end if if (theLine contains "[image:") or (theLine contains "[zoomImage:") then set imageOffset to offset("image:", theLine) + 6 set theSearchString to char imageOffset to length(theLine) of theLine set imageList to returnThreeNamesList(theSearchString) if theLine contains "[zoom" then addProp(newPage, #zoomImage, imageList) else addProp(newPage, #pageImage, imageList) end if set lastInterestingLine to currentLine end if if theLine contains "[movie" then set movieOffset to offset("[movie:", theLine) + 7 set theSearchString to char movieOffset to length(theLine) of theLine set movieList to returnThreeNamesList(theSearchString) set movieName to getAt(movieList, 2) if (movieName contains ".dir") or (movieName contains ".dxr") then addProp(newPage, #pageMovieInAWindow, movieList) else addProp(newPage, #pageMovie, movieList) end if set lastInterestingLine to currentLine end if if theLine contains "[launch:" then set appOffset to offset("[launch:", theLine) + 8 set theSearchString to char appOffset to length(theLine) of theLine set newLaunchList to returnThreeNamesList(theSearchString) set the itemDelimiter to "," set launchString to getAt(newLaunchList, 1) set appName to item 1 of launchString set MacDocName to item 2 of launchString if MacDocName <> EMPTY then set MacDocName to makeHeaderFlush(MacDocName) end if set secondEntry to getAt(newLaunchList, 2) if secondEntry = launchString then set WIN16DocName to MacDocName else set WIN16DocName to makeHeaderFlush(secondEntry) end if set thirdEntry to getAt(newLaunchList, 3) if thirdEntry = secondEntry then set WIN32DocName to WIN16DocName else set WIN32DocName to makeHeaderFlush(thirdEntry) end if set launchNames to appName & "," & MacDocName & "," & WIN16DocName & "," & WIN32DocName if listp(getaProp(newPage, #PageLaunch)) then append(getProp(newPage, #PageLaunch), launchNames) else addProp(newPage, #PageLaunch, [launchNames]) end if set lastInterestingLine to currentLine end if if theLine contains "[application" then set appOffset to offset("[application:", theLine) + 13 set theSearchString to char appOffset to length(theLine) of theLine set appList to returnThreeNamesList(theSearchString) addProp(newPage, #pageApp, appList) set lastInterestingLine to currentLine end if if theLine contains "{p}" then if lastInterestingLine < currentLine then set StrippedTextCast to theStrippedCastNum set PageText to string(lastInterestingLine + 1) && currentLine && StrippedTextCast addProp(newPage, #PageText, PageText) end if set pageCounter to pageCounter + 1 set lastInterestingLine to currentLine append(newPageList, newPage) set newPage to [:] end if set currentLine to currentLine + 1 if TenPercentLines > 0 then if (currentLine mod TenPercentLines) = 0 then set percentDone to currentLine / TenPercentLines * 10 put string(percentDone) & "% complete..." end if end if end repeat if currentLevel > 1 then set newMenuList to finishMenuLevel(newMenu, newPage, newPageList, newMenuList) return [newMenuList, currentLine] end if set newMenuList to finishMenuLevel(newMenu, newPage, newPageList, newMenuList) return newMenuList cursor(0) end on testParse theSearchString set newLaunchList to returnThreeNamesList(theSearchString) set the itemDelimiter to "," set launchString to getAt(newLaunchList, 1) set appName to item 1 of launchString set MacDocName to item 2 of launchString if MacDocName <> EMPTY then set MacDocName to makeHeaderFlush(MacDocName) end if set secondEntry to getAt(newLaunchList, 2) if secondEntry = launchString then set WIN16DocName to MacDocName else set WIN16DocName to makeHeaderFlush(secondEntry) end if set thirdEntry to getAt(newLaunchList, 3) if thirdEntry = secondEntry then set WIN32DocName to WIN16DocName else set WIN32DocName to makeHeaderFlush(thirdEntry) end if set launchNames to appName & "," & MacDocName & "," & WIN16DocName & "," & WIN32DocName put launchNames end on returnThreeNamesList theSearchString set theNameList to [] repeat with nameNum = 1 to 3 set nextNameList to getNextName(theSearchString) set nextName to getAt(nextNameList, 1) set theSearchString to getAt(nextNameList, 2) append(theNameList, nextName) end repeat set MacName to getAt(theNameList, 1) set WIN16Name to getAt(theNameList, 2) if WIN16Name = EMPTY then setAt(theNameList, 2, MacName) setAt(theNameList, 3, MacName) else if getAt(theNameList, 3) = EMPTY then setAt(theNameList, 3, WIN16Name) end if end if return value(string(theNameList)) end on getNextName theLine repeat with i = 1 to length(theLine) if char i of theLine <> " " then if theLine contains "/" then set imageEnd to offset("/", theLine) else set imageEnd to offset("]", theLine) end if set imageName to char i to imageEnd - 1 of theLine if imageName = "]" then set imageName to EMPTY end if delete char 1 to imageEnd of theLine return [imageName, theLine] exit repeat end if end repeat return [EMPTY, EMPTY] end on finishMenuLevel aMenu, aPage, aPageList, aMenuList if count(aMenu) > 0 then if count(aPage) > 0 then append(aPageList, aPage) end if addProp(aMenu, #PageList, aPageList) append(aMenuList, aMenu) end if return aMenuList end on addAnchorToList anchorNum, theList set existsAlready to getaProp(anchorList, anchorNum) if not voidp(existsAlready) then alert("anchor " & anchorNum & " is defined multiple times!!") else addProp(anchorList, anchorNum, theList) end if end on addJumptoList theWord, jumpNum, theList set existingWordList to getaProp(JumpList, theWord) if not voidp(existingWordList) then addProp(existingWordList, jumpNum, string(theList)) setProp(JumpList, theWord, existingWordList) else set newWordList to [:] addProp(newWordList, jumpNum, string(theList)) addProp(JumpList, theWord, newWordList) end if end on stripChars whatText, startChar, endChar set startAt to offset(startChar, whatText) set endAt to offset(endChar, whatText) set len to length(whatText) set newString to EMPTY if startAt > 1 then set newString to char 1 to startAt - 1 of whatText end if if endAt < len then put char endAt + 1 to len of whatText after newString end if return newString end on getMenuDepth aHeading set extraChar to EMPTY repeat with i = 1 to length(aHeading) set theChar to char i of aHeading if theChar = "+" then set extraChar to theChar end if if not (" +" contains theChar) then return [(i + 1) / 3, extraChar] end if end repeat end on makeHeaderFlush aHeading set len to length(aHeading) repeat with i = 1 to len set theChar to char i of aHeading if theChar = "+" then set extraChar to theChar end if if not (" +" contains theChar) then return char i to len of aHeading end if end repeat end on stripReturnAtEnd theString set theLineCount to the number of lines in theString if line theLineCount of theString = EMPTY then delete line theLineCount of theString end if return theString end on getSpecificMenu aMenuHierarchy, theStartLevel, theMenuList global theMenuString set theMenuString to EMPTY doGetSpecificMenu(aMenuHierarchy, theMenuList, theStartLevel, 1) return stripReturnAtEnd(theMenuString) end on doGetSpecificMenu aMenuHierarchy, theMenuList, theStartLevel, theLevel global theMenuString repeat with menuCounter = 1 to count(theMenuList) set theMenu to getAt(theMenuList, menuCounter) set theMenuName to getProp(theMenu, #MenuHeading) if theLevel >= theStartLevel then put theMenuName & RETURN after theMenuString end if if theLevel <= count(aMenuHierarchy) then if menuCounter = getAt(aMenuHierarchy, theLevel) then if listp(getaProp(theMenu, #SubMenu)) then doGetSpecificMenu(aMenuHierarchy, getaProp(theMenu, #SubMenu), theStartLevel, theLevel + 1) end if end if end if end repeat end on getAllMenus theMenuList global theMenuString set theMenuString to EMPTY doGetMenu(theMenuList, 1, 99) return stripReturnAtEnd(theMenuString) end on getMenu theMenuList, stripCharsBool global theMenuString set theMenuString to EMPTY doGetMenu(theMenuList, 1, 1) if stripCharsBool then repeat with i = 1 to the number of lines in theMenuString if char 3 of line i of theMenuString = " " then delete char 3 of line i of theMenuString end if delete char 1 to 2 of line i of theMenuString end repeat end if return stripReturnAtEnd(theMenuString) end on doGetMenu theMenuList, theLevel, howManyLevelsDeep global theMenuString set theCount to count(theMenuList) if theCount > 0 then repeat with menuCounter = 1 to theCount set theMenu to getAt(theMenuList, menuCounter) set theMenuName to getaProp(theMenu, #MenuHeading) put theMenuName & RETURN after theMenuString if listp(getaProp(theMenu, #SubMenu)) and (theLevel < howManyLevelsDeep) then doGetMenu(getaProp(theMenu, #SubMenu), theLevel + 1, howManyLevelsDeep) end if end repeat end if end